/*
 * @Author: your name
 * @Date: 2021-05-11 11:34:12
 * @LastEditTime: 2021-05-11 22:13:29
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \studygo\锁\等待组\main.go
 */
package main

import (
	"fmt"
	"strconv"
	"sync"
	"time"
)

func main() {

	var waitGroup sync.WaitGroup
	//添加等待groutine数量为5
	waitGroup.Add(5)
	for i := 0; i < 5; i++ {
		go func(i int) {
			fmt.Println("work func " + strconv.Itoa(i) + " is done at" + time.Now().String())
			time.Sleep(time.Second)
			waitGroup.Done()
		}(i)
	}
	waitGroup.Wait()
	fmt.Println("all works are done at" + time.Now().String())

}
